﻿// Code goes here

angular.module('app', []);

angular.module('app').controller('mainCtrl', function ($scope) {
    $scope.user1 = {
        name: 'Luke Skywalker',
        address: {
            street: 'PO Box 123',
            city: 'Secret Rebel Base',
            planet: 'Yavin 4'
        },
        friends: [
          'Han',
          'Leia',
          'Chewbacca'
        ]
    }
    $scope.user2 = {
        name: 'Han Solo',
        address: {
            street: 'PO Box 123',
            city: 'Mos Eisley',
            planet: 'Tattoine'
        },
        friends: [
          'Han',
          'Leia',
          'Chewbacca'
        ]
    }

});

angular.module('app').directive('userInfoCard', function () {
    return {
        templateUrl: "/app/templates/userInfoCard.html",
        restrict: "E",
        scope: {
            user: '='
        },
        controller: function ($scope) {
            $scope.collapsed = false;
            $scope.knightMe = function (user) {
                user.rank = "knight";
            }
            $scope.collapse = function () {
                $scope.collapsed = !$scope.collapsed;
            }
        }
    }
});

angular.module('app').directive('address', function () {
    return {
        restrict: 'E',
        scope: true,
        templateUrl: '/app/templates/address.html',
        controller: function ($scope) {
            $scope.collapsed = false;
            $scope.collapseAddress = function () {
                $scope.collapsed = true;
            }
            $scope.expandAddress = function () {
                $scope.collapsed = false;
            }
        }
    }
});













